package com.tjmntv.tj.myapplication.demo1

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.tjmntv.tj.myapplication.R
import kotlinx.android.synthetic.main.aty_kotlin_demo_01.*

/**
 * @author wzw
 * @date 2021/8/16 13:51
 */
class KotlinDemo1 : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.aty_kotlin_demo_01)
        val viewModel: MyViewModel = ViewModelProvider(this).get(MyViewModel::class.java);
        viewModel.number.observe(this, Observer { textView.text = it.toString() })
        var number = 0
        textView.text = "0"
        button1.setOnClickListener {
            viewModel.modifyMuner(1)
        }
        button2.setOnClickListener {
            viewModel.modifyMuner(-1)
        }
    }
}